package cn.lazyturtle.bugpush.service.dingdingcallback.addressbookevents;

import cn.lazyturtle.bugpush.dao.user.UserDao;
import cn.lazyturtle.bugpush.jooq.tables.pojos.BUser;
import cn.lazyturtle.bugpush.service.dingdingcallback.DingDingCallBackHandlerFactory;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * UserModifyOrgHandler : 用户修改通讯录
 * </p>
 *
 * @author cwh
 * @since 2021-10-25
 */
@Component
@Slf4j
public class UserLeaveOrgHandler extends AbstractAddressBookEventsHandler{
    private final UserDao userDao;

    @Autowired
    public UserLeaveOrgHandler(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void dealEvent(JSONObject callBackContent) {
        log.info("通讯录用户离职,callBackContent:{},",callBackContent);
        String userIdList = callBackContent.getString("UserId");
        List<String> userIds = JSONObject.parseArray(userIdList,String.class);
        String userId = userIds.get(0);
        userDao.deleteUserByDingDingId(userId);
    }

    @Override
    public void afterPropertiesSet() {
        DingDingCallBackHandlerFactory.register(USER_LEAVE_ORG, this);
    }
}
